<?php

declare(strict_types=1);

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class RegisterRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
     */
    public function rules(): array
    {
        return [
            'email' => 'required|email|max:255|unique:users,email',
            'password' => [
                'required',
                'confirmed',
                'min:8',
            ],
            'password_confirmation' => 'required|same:password',
            'invite_code' => 'sometimes|nullable|string|max:50',
            'agree_terms' => 'accepted',
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array<string, string>
     */
    public function messages(): array
    {
        return [
            'email.required' => '请输入邮箱地址',
            'email.email' => '请输入有效的邮箱地址',
            'email.max' => '邮箱地址不能超过255个字符',
            'email.unique' => '该邮箱已被注册',
            'password.required' => '请输入密码',
            'password.confirmed' => '两次输入的密码不一致',
            'password_confirmation.required' => '请确认密码',
            'password_confirmation.same' => '两次输入的密码不一致',
            'invite_code.max' => '邀请码不能超过50个字符',
            'agree_terms.accepted' => '请同意服务条款和隐私政策',
        ];
    }
} 